local yehuo = fk.CreateSkill {
  name = "lingling__yehuo",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lingling__yehuo"] = "业火",
  [":lingling__yehuo"] = "出牌阶段限一次，你可以将手牌调整至三张，视为使用【火攻】，若你因此弃置牌，则之伤害+1。",

  ["#lingling__yehuo"] = "业火：将手牌调整至三张，视为使用%arg【火攻】。",

  ["#lingling__yehuo_plus"] = "伤害+1的",
}

yehuo:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  pattern = "fire_attack",
  max_phase_use_time = 1,
  prompt = function(self, player)
    local arg = ""
    local num = player:getHandcardNum() - 3
    if num > 0 then
      arg = "#lingling__yehuo_plus"
    end
    return "#lingling__yehuo:::" .. arg
  end,
  card_num = function(self, player)
    local num = player:getHandcardNum() - 3
    return math.max(num, 0)
  end,
  card_filter = function(self, player, to_select, selected)
    local num = player:getHandcardNum() - 3
    if num > 0 then
      local room = Fk:currentRoom()
      return #selected < num and room:getCardArea(to_select) == player.Hand and room:getCardOwner(to_select) == player
    end
    return false
  end,
  view_as = function(self, player, cards)
    if player:getHandcardNum() - 3 > #cards then return end
    local card = Fk:cloneCard("fire_attack")
    card:addFakeSubcards(cards)
    card.skillName = yehuo.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local x = 3 - player:getHandcardNum()
    if x > 0 then
      player:drawCards(x, yehuo.name)
    else
      room:throwCard(use.card.fake_subcards, yehuo.name, player, player)
      use.additionalDamage = (use.additionalDamage or 0) + 1
    end
  end,
  enabled_at_play = function(self, player)
    return player:getHandcardNum() ~= 3 and self:withinTimesLimit(player, Player.HistoryPhase)
  end,
  enabled_at_response = Util.FalseFunc,
})

return yehuo
